package com.fengye.algorithms.huawei;

import java.util.*;

/**
 * https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3?tpId=37&tqId=21268&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
 * @Author fengye
 * @Date 2023/3/9 17:54
 **/
public class BeautifulName {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            List<String> list = new ArrayList<>();
            for (int i = 0; i <n;i++) {
                list.add(in.next());
            }

            for(String name : list) {
                // 把相同的字符找出来
                Map<Character, Integer> map = new HashMap<>();
                for (int i = 0; i < name.length();i++) {
                    char c = name.charAt(i);
                    if(map.containsKey(c)) {
                        map.put(c, map.get(c) + 1);
                    } else {
                        map.put(c, 1);
                    }
                }
                // 按个数排序
                List<Map.Entry<Character, Integer>> entryList = new ArrayList<>(map.entrySet());
                Collections.sort(entryList, new Comparator<Map.Entry<Character, Integer>>(){
                    @Override
                    public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
                        return o2.getValue() - o1.getValue();
                    }
                });
                int res = 0;
                for (int i = 0; i < entryList.size();i++) {
                    Map.Entry<Character, Integer> entry= entryList.get(i);
                    res += entry.getValue() * (26-i);
                }
                System.out.println(res);

            }
        }
    }


}
